package com.lemon.smartsafetynew.ui.activity.base;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.KeyEvent;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.AppManager;

/**
 * Created by Cooliean on 16/3/20.
 */
public abstract class BaseFragmentActivity extends SwipeBackActivity {
    @Override
    protected void callFinish() {
        AppManager.getAppManager().finishActivity(this);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_fragment_swipe;
    }

    @Override
    protected void initViews() {
        super.initViews();
    }


    public abstract Fragment getFragment();


    @Override
    public void baseOnCreate(Bundle savedInstanceState) {
        super.baseOnCreate(savedInstanceState);
        if (savedInstanceState == null && null != getFragment()) {
            getSupportFragmentManager().beginTransaction().add(R.id.main_content, getFragment(), this.getClass().getName()).commit();
        }
    }



    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            callFinish();
        }
        return super.onKeyDown(keyCode, event);
    }
}
